package com.code.drawable

import android.graphics.drawable.Drawable

/**
 * Created by RLZ
 * on 2021/5/18
 *
 * 添加几种常用的 背景样式
 */
class DrawableFactory {

    companion object {
        /**
         * 带padding的
         */
        @JvmStatic
        fun pd(color: Int, radius: Float, padding: Int): Drawable =
            insetDrawable {
                drawable = shapeDrawable {
                    corner(radius)
                    solid(color)
                }
                setInset(padding)
            }

        /**
         * 圆锥形
         */
        @JvmStatic
        fun oval(color: Int): Drawable {
            return shapeDrawable {
                shape(Shape.RECTANGLE)
                solid(color)
            }
        }

        /**
         * 矩形
         */
        @JvmStatic
        fun rectangle(color: Int): Drawable {
            return shapeDrawable {
                shape(Shape.RECTANGLE)
                solid(color)
            }
        }

        /**
         * 圆角矩形
         */
        @JvmStatic
        fun rectangle(color: Int, radius: Float): Drawable {
            return shapeDrawable {
                shape(Shape.RECTANGLE)
                solid(color)
                corner(radius)
            }
        }

        /**
         * 渐变色
         * angle 必须为45的倍数
         */
        @JvmStatic
        fun gradient(radius: Float, startColor: Int, endColor: Int): Drawable {
            return gradient(180, radius, startColor, endColor)
        }

        @JvmStatic
        fun gradient(radius: Float, startColor: Int, endColor: Int, centerColor: Int): Drawable {
            return gradient(180, radius, startColor, endColor, centerColor)
        }

        @JvmStatic
        fun gradient(angle: Int, radius: Float, startColor: Int, endColor: Int): Drawable {
            return shapeDrawable {
                corner(radius)
                gradient(angle, startColor, endColor)
            }
        }

        @JvmStatic
        fun gradient(
            angle: Int,
            radius: Float,
            startColor: Int,
            endColor: Int,
            centerColor: Int
        ): Drawable {
            return shapeDrawable {
                corner(radius)
                gradient(angle, startColor, endColor, centerColor)
            }
        }


        /**
         * 边框 内部透明 圆形
         */
        @JvmStatic
        fun stroke(color: Int, width: Float): Drawable {
            return shapeDrawable {
                shape(Shape.OVAL)
                solid(android.R.color.transparent)
                stroke(color, width)
            }
        }

        /**
         * 边框  矩形或圆角矩形
         */
        @JvmStatic
        fun stroke(radius: Float, color: Int, width: Float): Drawable {
            return shapeDrawable {
                shape(Shape.RECTANGLE)
                corner(radius)
                solid(android.R.color.transparent)
                stroke(color, width)
            }
        }
    }
}